// pages/management/management.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputValue: null,
    hiddenmodalput: true,
    hiddenmodalput_1: true,
    stu_num: '',
    stu_name: '',
    course_num: '',
    show: true,
    loading: false
  },

  setTap: function(e) {
    var that = this
    var id = e.currentTarget.dataset.index
    var course_num = this.data.list[id].cou_info_course_num
    this.setData({
      course_num: course_num
    })
    wx.showActionSheet({
      itemList: ['设置学生管理员权限'],
      success(res) {
        that.setData({
          hiddenmodalput: !that.data.hiddenmodalput
        })
      },
      fail(res) {

      }
    })
  },

  getNum: function(e) {
    wx.setStorageSync("stu_num", e.detail.value)
  },

  cancel: function() {
    this.setData({
      hiddenmodalput: true
    })
  },

  confirm: function() {
    var that = this
    var stu_num = wx.getStorageSync("stu_num")
    var header = app.globalData.header
    if (stu_num != "") {
      wx.request({
        url: 'http://139.199.192.171:8080/nanitao/Student/confirmInfo.action',
        dataType: 'json',
        data: {
          stu_num: stu_num
        },
        method: 'GET',
        header: header,
        success: function(res) {
          var msg = res.data
          var stu_num = msg.stu_num
          var stu_name = msg.stu_name
          that.setData({
            stu_num: stu_num,
            stu_name: stu_name,
            hiddenmodalput: true,
            hiddenmodalput_1: !that.data.hiddenmodalput_1
          })
        }
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '学号不能为空，请输入学号',
      })
    }
  },

  cancel_1: function() {
    this.setData({
      hiddenmodalput_1: true,
      inputValue: ''
    })
    wx.removeStorage({
      key: 'stu_num'
    })
  },

  confirm_1: function() {
    var that = this
    var stu_num = wx.getStorageSync("stu_num")
    var tea_num = wx.getStorageSync("username")
    var course_num = this.data.course_num
    var header = app.globalData.header
    wx.request({
      url: 'http://139.199.192.171:8080/nanitao/Student/SetAdmin.action',
      data: {
        stu_num: stu_num,
        cou_info_couse_num: course_num,
      },
      method: 'POST',
      header: header,
      success: function(res) {
        if (res.data === 1) {
          wx.showModal({
            title: '提示',
            content: '设置成功',
            showCancel: false
          })
        }
        that.setData({
          hiddenmodalput_1: true,
          inputValue: null,
        })
        that.courseListRequest(tea_num)
        wx.removeStorageSync("stu_num")
      }

    })
  },

  courseListRequest: function(tea_num) {
    var header = app.globalData.header
    var that = this
    wx.request({
      url: 'http://139.199.192.171:8080/nanitao/tea_course_info/list.action',
      method: 'GET',
      header: header,
      data: {
        tea_num: tea_num
      },
      success: function(res) {
        that.setData({
          list: res.data,
          loading: false
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      loading: true
    })
    var tea_num = wx.getStorageSync("username")
      this.courseListRequest(tea_num)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})